package br.usp.icmc.lasdpc.gem.com;

import java.io.Serializable;
import java.net.InetSocketAddress;

/**
 * A abstraction for message in order to send through the network. This class
 * is intended to simplify the use of the communication, once most often the 
 * user or the programmer wants to send an object.
 * <p>
 * When a peer in the network wants to send data to another peer, it simply
 * creates a new message, set its tag and send to a destination a given object
 * that is the pay load from it.
 * <p>
 * The tag field allows create a type of protocol, which means the use can
 * invoke a especific function for a given value of tag. 
 * 
 * @author Lourenco Alves
 *
 */
@SuppressWarnings("serial")
public class Message implements Serializable {

	/** A tag for the instantiated Message */
	private byte tag;
	/** An object desired to send, in other words the content of the message */
	private Object payLoad;
	/** The sender of the message, can be used by the receiver to reply */
	private InetSocketAddress source;
	/** The destination of the message */
	private InetSocketAddress destination;
	
	/**
	 * Create a new message to be sent based on the parameters
	 * 
	 * @param tag value to be used as tag
	 * @param source the sender of the message
	 * @param destination the destination of the message
	 * @param payLoad represents the content of the message
	 */
	public Message(byte tag, InetSocketAddress source, InetSocketAddress destination, 
			Object payLoad) {
		this.tag = tag;
		this.source = source;
		this.destination = destination;
		this.payLoad = payLoad;
	}
	
	/**
	 * Get method for source
	 * @return
	 */
	public InetSocketAddress getSource() {
		return source;
	}

	/**
	 * Set method for source
	 * @param source
	 */
	public void setSource(InetSocketAddress source) {
		this.source = source;
	}

	/**
	 * Get method for destination
	 * @return
	 */
	public InetSocketAddress getDestination() {
		return destination;
	}

	/**
	 * Set method for destination
	 * @param destination
	 */
	public void setDestination(InetSocketAddress destination) {
		this.destination = destination;
	}

	/**
	 * Get method for tag
	 * @return
	 */
	public byte getTag() {
		return tag;
	}

	/**
	 * Set method for tag
	 * @param tag
	 */
	public void setTag(byte tag) {
		this.tag = tag;
	}

	/**
	 * Get method for payLoad
	 * @return
	 */
	public Object getPayLoad() {
		return payLoad;
	}

	/**
	 * Set method for payLoad
	 * @param payLoad
	 */
	public void setPayLoad(Object payLoad) {
		this.payLoad = payLoad;
	}
	

}
